
#ifndef _GOOGLEBUZZTOKENFORM_H_
#define _GOOGLEBUZZTOKENFORM_H_

#include <FBase.h>
#include <FUi.h>
#include "../../../inc/Utility/Json/JsonReader.h"
#include <FWeb.h>
#include "../../../inc/Ui/FormManager.h"
#include <FMedia.h>
#include <FGraphics.h>
#include <FNet.h>

using namespace Osp::Ui;
using namespace Osp::Base;
using namespace Osp::Ui::Controls;
using namespace Osp::Web::Controls;
using namespace Osp::Media;
using namespace Osp::Graphics;
using namespace Osp::Net::Http;

class GoogleBuzzTokenForm :
	public Osp::Ui::Controls::Form,
	public Osp::Ui::IActionEventListener,
	public Osp::Web::Controls::ILoadingListener,
	public IHttpTransactionEventListener,
	public Osp::Ui::IAnimationEventListener
{

// Construction
public:
	GoogleBuzzTokenForm(void);
	virtual ~GoogleBuzzTokenForm(void);
	bool Initialize();
	result OnInitializing(void);
	result OnTerminating(void);
	void GetTokent(void);

// Implementation
protected:
	void ProcessGetToken(HttpSession &httpSession,HttpTransaction &httpTransaction);
	void Download(String url, ByteBuffer *pBody, HttpHeader *pHeader, NetHttpMethod method);

	virtual void  OnActionPerformed (const Osp::Ui::Control &source, int actionId);
	virtual void  OnLoadingErrorOccurred (LoadingErrorType error, const Osp::Base::String &reason);
	virtual void  OnPageTitleReceived (const Osp::Base::String &title);
	virtual void  OnTransactionReadyToRead (HttpSession &httpSession, HttpTransaction &httpTransaction, int availableBodyLen);

	virtual void  OnAnimationStopped (const Osp::Ui::Control &source){}
	virtual void  OnEstimatedProgress (int progress){}
	virtual void  OnHttpAuthenticationCanceled (void){}
	virtual bool  OnHttpAuthenticationRequestedN (const Osp::Base::String &host, const Osp::Base::String &realm,
				const Osp::Web::Controls::AuthenticationChallenge &authentication){ return false;}
	virtual void  OnLoadingCanceled (void){}
	virtual void  OnLoadingCompleted (void){}
	virtual bool  OnLoadingRequested (const Osp::Base::String &url, WebNavigationType type){ return false;}
	virtual void  OnLoadingStarted (void){}
	virtual DecisionPolicy OnWebDataReceived (const Osp::Base::String &mime,
			const Osp::Net::Http::HttpHeader &httpHeader){
		return WEB_DECISION_CONTINUE;
	}
	virtual void  OnTransactionAborted (HttpSession &httpSession, HttpTransaction &httpTransaction, result r){}
	virtual void  OnTransactionCertVerificationRequiredN (HttpSession &httpSession, HttpTransaction &httpTransaction, Osp::Base::String *pCert){}
	virtual void  OnTransactionCompleted (HttpSession &httpSession, HttpTransaction &httpTransaction){}
	virtual void  OnTransactionHeaderCompleted (HttpSession &httpSession, HttpTransaction &httpTransaction, int headerLen, bool bAuthRequired){}

	virtual void  OnTransactionReadyToWrite (HttpSession &httpSession, HttpTransaction &httpTransaction, int recommendedChunkSize){}


	Web *pWeb;

	String code;
	String clientID;
	String clientSecret;
	String redirectUri;
	String apiKey;
	String accessToken;
	String refreshToken;

	//animation
	Osp::Ui::Controls::Animation *pAnimation;
	Osp::Base::Collection::ArrayList animationFrameList;
	Popup *pDownloadPopup;

	void ShowPopup(void);
// Generated call-back functions
public:
	const static int ID_SOFTKEY_CANCEL = 1;
};

#endif
